<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Linux命令," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照，就是执行ps命令的那个时刻的那些进程，如果想要动态的显示进程信息，就可以使用top命令。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">
<meta name="keywords" content="Linux命令">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux 命令- ps">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/43. Linux 命令- ps/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照，就是执行ps命令的那个时刻的那些进程，如果想要动态的显示进程信息，就可以使用top命令。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T08:36:00.363Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux 命令- ps">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照，就是执行ps命令的那个时刻的那些进程，如果想要动态的显示进程信息，就可以使用top命令。 &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/43. Linux 命令- ps/"/>





  <title>Linux 命令- ps | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/2. Linux 命令/43. Linux 命令- ps/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Linux 命令- ps</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T01:57:34+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Linux中的ps命令是Process Status的缩写。ps命令用来列出系统中当前运行的那些进程。ps命令列出的是当前那些进程的快照，就是执行ps命令的那个时刻的那些进程，如果想要动态的显示进程信息，就可以使用top命令。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;要对进程进行监测和控制，首先必须要了解当前进程的情况，也就是需要查看当前进程，而 ps 命令就是最基本同时也是非常强大的进程查看命令。使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。总之大部分信息都是可以通过执行该命令得到的。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ps 为我们提供了进程的一次性的查看，它所提供的查看结果并不动态连续的；如果想对进程时间监控，应该用 top 工具。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;kill 命令用于杀死进程。</p>
<ul>
<li><p><strong>inux上进程有5种状态:</strong> </p>
<ul>
<li>运行(正在运行或在运行队列中等待) </li>
<li>中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) </li>
<li>不可中断(收到信号不唤醒和不可运行, 进程必须等待直到有中断发生) </li>
<li>僵死(进程已终止, 但进程描述符存在, 直到父进程调用wait4()系统调用后释放) </li>
<li>停止(进程收到SIGSTOP, SIGSTP, SIGTIN, SIGTOU信号后停止运行运行) </li>
</ul>
</li>
<li><p><strong>ps工具标识进程的5种状态码:</strong> </p>
<ul>
<li>D 不可中断 uninterruptible sleep (usually IO) </li>
<li>R 运行 runnable (on run queue) </li>
<li>S 中断 sleeping </li>
<li>T 停止 traced or stopped </li>
<li>Z 僵死 a defunct (”zombie”) process </li>
</ul>
</li>
</ul>
<h2 id="1．命令格式"><a href="#1．命令格式" class="headerlink" title="1．命令格式"></a>1．命令格式</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps[参数]</div></pre></td></tr></table></figure>
<h2 id="2．命令功能"><a href="#2．命令功能" class="headerlink" title="2．命令功能"></a>2．命令功能</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用来显示当前进程的状态</p>
<h2 id="3．命令参数"><a href="#3．命令参数" class="headerlink" title="3．命令参数"></a>3．命令参数</h2><ul>
<li>a  显示所有进程</li>
<li>-a 显示同一终端下的所有程序</li>
<li>-A 显示所有进程</li>
<li>c  显示进程的真实名称</li>
<li>-N 反向选择</li>
<li>-e 等于“-A”</li>
<li>e  显示环境变量</li>
<li>f  显示程序间的关系</li>
<li>-H 显示树状结构</li>
<li>r  显示当前终端的进程</li>
<li>T  显示当前终端的所有程序</li>
<li>u  指定用户的所有进程</li>
<li>-au 显示较详细的资讯</li>
<li>-aux 显示所有包含其他使用者的行程 </li>
<li>-C&lt;命令&gt; 列出指定命令的状况</li>
<li>–lines&lt;行数&gt; 每页显示的行数</li>
<li>–width&lt;字符数&gt; 每页显示的字符数</li>
<li>–help 显示帮助信息</li>
<li>–version 显示版本显示</li>
</ul>
<h2 id="4．使用实例"><a href="#4．使用实例" class="headerlink" title="4．使用实例"></a>4．使用实例</h2><h3 id="实例1：显示所有进程信息"><a href="#实例1：显示所有进程信息" class="headerlink" title="实例1：显示所有进程信息"></a>实例1：显示所有进程信息</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -A</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -A</span></div><div class="line">  PID TTY          TIME CMD</div><div class="line">    1 ?        00:00:00 init</div><div class="line">    2 ?        00:00:01 migration/0</div><div class="line">    3 ?        00:00:00 ksoftirqd/0</div><div class="line">    4 ?        00:00:01 migration/1</div><div class="line">    5 ?        00:00:00 ksoftirqd/1</div><div class="line">    6 ?        00:29:57 events/0</div><div class="line">    7 ?        00:00:00 events/1</div><div class="line">    8 ?        00:00:00 khelper</div><div class="line">   49 ?        00:00:00 kthread</div><div class="line">   54 ?        00:00:00 kblockd/0</div><div class="line">   55 ?        00:00:00 kblockd/1</div><div class="line">   56 ?        00:00:00 kacpid</div><div class="line">  217 ?        00:00:00 cqueue/0</div><div class="line">  ……省略部分结果</div></pre></td></tr></table></figure>
<h3 id="实例2：显示指定用户信息"><a href="#实例2：显示指定用户信息" class="headerlink" title="实例2：显示指定用户信息"></a>实例2：显示指定用户信息</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -u root</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -u root</span></div><div class="line">  PID TTY          TIME CMD</div><div class="line">    1 ?        00:00:00 init</div><div class="line">    2 ?        00:00:01 migration/0</div><div class="line">    3 ?        00:00:00 ksoftirqd/0</div><div class="line">    4 ?        00:00:01 migration/1</div><div class="line">    5 ?        00:00:00 ksoftirqd/1</div><div class="line">    6 ?        00:29:57 events/0</div><div class="line">    7 ?        00:00:00 events/1</div><div class="line">    8 ?        00:00:00 khelper</div><div class="line">   49 ?        00:00:00 kthread</div><div class="line">   54 ?        00:00:00 kblockd/0</div><div class="line">   55 ?        00:00:00 kblockd/1</div><div class="line">   56 ?        00:00:00 kacpid</div><div class="line">    ……省略部分结果</div></pre></td></tr></table></figure>
<h3 id="实例3：显示所有进程信息，连同命令行"><a href="#实例3：显示所有进程信息，连同命令行" class="headerlink" title="实例3：显示所有进程信息，连同命令行"></a>实例3：显示所有进程信息，连同命令行</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -ef</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -ef</span></div><div class="line">UID        PID  PPID  C STIME TTY          TIME CMD</div><div class="line">root         1     0  0 Nov02 ?        00:00:00 init [3]                  </div><div class="line">root         2     1  0 Nov02 ?        00:00:01 [migration/0]</div><div class="line">root         3     1  0 Nov02 ?        00:00:00 [ksoftirqd/0]</div><div class="line">root         4     1  0 Nov02 ?        00:00:01 [migration/1]</div><div class="line">root         5     1  0 Nov02 ?        00:00:00 [ksoftirqd/1]</div><div class="line">root         6     1  0 Nov02 ?        00:29:57 [events/0]</div><div class="line">root         7     1  0 Nov02 ?        00:00:00 [events/1]</div><div class="line">root         8     1  0 Nov02 ?        00:00:00 [khelper]</div><div class="line">root        49     1  0 Nov02 ?        00:00:00 [kthread]</div><div class="line">root        54    49  0 Nov02 ?        00:00:00 [kblockd/0]</div><div class="line">root        55    49  0 Nov02 ?        00:00:00 [kblockd/1]</div><div class="line">root        56    49  0 Nov02 ?        00:00:00 [kacpid]</div><div class="line">……省略部分结果</div></pre></td></tr></table></figure>
<h3 id="实例4：-ps-与grep-常用组合用法，查找特定进程"><a href="#实例4：-ps-与grep-常用组合用法，查找特定进程" class="headerlink" title="实例4： ps 与grep 常用组合用法，查找特定进程"></a>实例4： ps 与grep 常用组合用法，查找特定进程</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -ef|grep ssh</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -ef|grep ssh</span></div><div class="line">root      2720     1  0 Nov02 ?        00:00:00 /usr/sbin/sshd</div><div class="line">root     17394  2720  0 14:58 ?        00:00:00 sshd: root@pts/0 </div><div class="line">root     17465 17398  0 15:57 pts/0    00:00:00 grep ssh</div></pre></td></tr></table></figure>
<h3 id="实例5：将目前属于您自己这次登入的-PID-与相关信息列示出来"><a href="#实例5：将目前属于您自己这次登入的-PID-与相关信息列示出来" class="headerlink" title="实例5：将目前属于您自己这次登入的 PID 与相关信息列示出来"></a>实例5：将目前属于您自己这次登入的 PID 与相关信息列示出来</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -l</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -l</span></div><div class="line">F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD</div><div class="line">4 S     0 17398 17394  0  75   0 - 16543 <span class="built_in">wait</span>   pts/0    00:00:00 bash</div><div class="line">4 R     0 17469 17398  0  77   0 - 15877 -      pts/0    00:00:00 ps</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong> </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;各相关信息的意义：</p>
<ul>
<li><p>F 代表这个程序的旗标 (flag)， 4 代表使用者为 super user</p>
</li>
<li><p>S 代表这个程序的状态 (STAT)，关于各 STAT 的意义将在内文介绍</p>
</li>
<li><p>UID 程序被该 UID 所拥有</p>
</li>
<li><p>PID 就是这个程序的 ID ！</p>
</li>
<li><p>PPID 则是其上级父程序的ID</p>
</li>
<li><p>C CPU 使用的资源百分比</p>
</li>
<li><p>PRI 这个是 Priority (优先执行序) 的缩写</p>
</li>
<li><p>NI 这个是 Nice 值，在下一小节我们会持续介绍</p>
</li>
<li><p>ADDR 这个是 kernel function，指出该程序在内存的那个部分。如果是个 running的程序，一般就是 “-“</p>
</li>
<li><p>SZ 使用掉的内存大小</p>
</li>
<li><p>WCHAN 目前这个程序是否正在运作当中，若为 - 表示正在运作</p>
</li>
<li><p>TTY 登入者的终端机位置</p>
</li>
<li><p>TIME 使用掉的 CPU 时间。</p>
</li>
<li><p>CMD 所下达的指令为何</p>
</li>
<li><p>在预设的情况下， ps 仅会列出与目前所在的 bash shell 有关的 PID 而已，所以， 当我使用 ps -l 的时候，只有三个 PID。</p>
</li>
</ul>
<h3 id="实例6：列出目前所有的正在内存当中的程序"><a href="#实例6：列出目前所有的正在内存当中的程序" class="headerlink" title="实例6：列出目前所有的正在内存当中的程序"></a>实例6：列出目前所有的正在内存当中的程序</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps aux</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps aux</span></div><div class="line">USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND</div><div class="line">root         1  0.0  0.0  10368   676 ?        Ss   Nov02   0:00 init [3]                  </div><div class="line">root         2  0.0  0.0      0     0 ?        S&lt;   Nov02   0:01 [migration/0]</div><div class="line">root         3  0.0  0.0      0     0 ?        SN   Nov02   0:00 [ksoftirqd/0]</div><div class="line">root         4  0.0  0.0      0     0 ?        S&lt;   Nov02   0:01 [migration/1]</div><div class="line">root         5  0.0  0.0      0     0 ?        SN   Nov02   0:00 [ksoftirqd/1]</div><div class="line">root         6  0.0  0.0      0     0 ?        S&lt;   Nov02  29:57 [events/0]</div><div class="line">root         7  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [events/1]</div><div class="line">root         8  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [khelper]</div><div class="line">root        49  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [kthread]</div><div class="line">root        54  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [kblockd/0]</div><div class="line">root        55  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [kblockd/1]</div><div class="line">root        56  0.0  0.0      0     0 ?        S&lt;   Nov02   0:00 [kacpid]</div><div class="line">……省略部分结果</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>说明</strong></p>
<ul>
<li><p>USER：该 process 属于那个使用者账号的</p>
</li>
<li><p>PID ：该 process 的号码</p>
</li>
<li><p>%CPU：该 process 使用掉的 CPU 资源百分比</p>
</li>
<li><p>%MEM：该 process 所占用的物理内存百分比</p>
</li>
<li><p>VSZ ：该 process 使用掉的虚拟内存量 (Kbytes)</p>
</li>
<li><p>RSS ：该 process 占用的固定的内存量 (Kbytes)</p>
</li>
<li><p>TTY ：该 process 是在那个终端机上面运作，若与终端机无关，则显示 ?，另外， tty1-tty6 是本机上面的登入者程序，若为 pts/0 等等的，则表示为由网络连接进主机的程序。</p>
</li>
<li><p>STAT：该程序目前的状态，主要的状态有</p>
</li>
<li><p>R ：该程序目前正在运作，或者是可被运作</p>
</li>
<li><p>S ：该程序目前正在睡眠当中 (可说是 idle 状态)，但可被某些讯号 (signal) 唤醒。</p>
</li>
<li><p>T ：该程序目前正在侦测或者是停止了</p>
</li>
<li><p>Z ：该程序应该已经终止，但是其父程序却无法正常的终止他，造成 zombie (疆尸) 程序的状态</p>
</li>
<li><p>START：该 process 被触发启动的时间</p>
</li>
<li><p>TIME ：该 process 实际使用 CPU 运作的时间</p>
</li>
<li><p>COMMAND：该程序的实际指令</p>
</li>
</ul>
<h3 id="实例7：列出类似程序树的程序显示"><a href="#实例7：列出类似程序树的程序显示" class="headerlink" title="实例7：列出类似程序树的程序显示"></a>实例7：列出类似程序树的程序显示</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -axjf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>*输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -axjf</span></div><div class="line">Warning: bad syntax, perhaps a bogus <span class="string">'-'</span>? See /usr/share/doc/procps-3.2.7/FAQ</div><div class="line"> PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND</div><div class="line">    0     1     1     1 ?           -1 Ss       0   0:00 init [3]                  </div><div class="line">    1     2     1     1 ?           -1 S&lt;       0   0:01 [migration/0]</div><div class="line">    1     3     1     1 ?           -1 SN       0   0:00 [ksoftirqd/0]</div><div class="line">    1     4     1     1 ?           -1 S&lt;       0   0:01 [migration/1]</div><div class="line">    1     5     1     1 ?           -1 SN       0   0:00 [ksoftirqd/1]</div><div class="line">    1     6     1     1 ?           -1 S&lt;       0  29:58 [events/0]</div><div class="line">    1     7     1     1 ?           -1 S&lt;       0   0:00 [events/1]</div><div class="line">    1     8     1     1 ?           -1 S&lt;       0   0:00 [khelper]</div><div class="line">    1    49     1     1 ?           -1 S&lt;       0   0:00 [kthread]</div><div class="line">   49    54     1     1 ?           -1 S&lt;       0   0:00  \_ [kblockd/0]</div><div class="line">   49    55     1     1 ?           -1 S&lt;       0   0:00  \_ [kblockd/1]</div><div class="line">   49    56     1     1 ?           -1 S&lt;       0   0:00  \_ [kacpid]</div></pre></td></tr></table></figure>
<h3 id="实例8：找出与-cron-与-syslog-这两个服务有关的-PID-号码"><a href="#实例8：找出与-cron-与-syslog-这两个服务有关的-PID-号码" class="headerlink" title="实例8：找出与 cron 与 syslog 这两个服务有关的 PID 号码"></a>实例8：找出与 cron 与 syslog 这两个服务有关的 PID 号码</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pa aux|egrep <span class="string">'(cron|syslog)'</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps aux | egrep '(cron|syslog)'</span></div><div class="line">root      2682  0.0  0.0  83384  2000 ?        Sl   Nov02   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5</div><div class="line">root      2735  0.0  0.0  74812  1140 ?        Ss   Nov02   0:00 crond</div><div class="line">root     17475  0.0  0.0  61180   832 pts/0    S+   16:27   0:00 egrep (cron|syslog)</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
<h3 id="其他实例："><a href="#其他实例：" class="headerlink" title="其他实例："></a>其他实例：</h3><h4 id="1-可以用-管道和-more-连接起来分页查看"><a href="#1-可以用-管道和-more-连接起来分页查看" class="headerlink" title="1. 可以用 | 管道和 more 连接起来分页查看"></a>1. 可以用 | 管道和 more 连接起来分页查看</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -aux |more</div></pre></td></tr></table></figure>
<h4 id="2-把所有进程显示出来，并输出到ps001-txt文件"><a href="#2-把所有进程显示出来，并输出到ps001-txt文件" class="headerlink" title="2. 把所有进程显示出来，并输出到ps001.txt文件"></a>2. 把所有进程显示出来，并输出到ps001.txt文件</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -aux &gt; ps001.txt</div></pre></td></tr></table></figure>
<h4 id="3-输出指定的字段"><a href="#3-输出指定的字段" class="headerlink" title="3. 输出指定的字段"></a>3. 输出指定的字段</h4><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>命令</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ps -o pid,ppid,pgrp,session,tpgid,comm</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>输出</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@localhost test6]<span class="comment"># ps -o pid,ppid,pgrp,session,tpgid,comm</span></div><div class="line">  PID  PPID  PGRP  SESS TPGID COMMAND</div><div class="line">17398 17394 17398 17398 17478 bash</div><div class="line">17478 17398 17478 17398 17478 ps</div><div class="line">[root@localhost test6]<span class="comment">#</span></div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Linux命令/" rel="tag"># Linux命令</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/68. Linux 命令- tr/" rel="next" title="Linux 命令- tr">
                <i class="fa fa-chevron-left"></i> Linux 命令- tr
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/2. Linux 命令/20. find 命令之 exec/" rel="prev" title="find 命令之 exec">
                find 命令之 exec <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1．命令格式"><span class="nav-number">1.</span> <span class="nav-text">1．命令格式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2．命令功能"><span class="nav-number">2.</span> <span class="nav-text">2．命令功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3．命令参数"><span class="nav-number">3.</span> <span class="nav-text">3．命令参数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4．使用实例"><span class="nav-number">4.</span> <span class="nav-text">4．使用实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例1：显示所有进程信息"><span class="nav-number">4.1.</span> <span class="nav-text">实例1：显示所有进程信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例2：显示指定用户信息"><span class="nav-number">4.2.</span> <span class="nav-text">实例2：显示指定用户信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例3：显示所有进程信息，连同命令行"><span class="nav-number">4.3.</span> <span class="nav-text">实例3：显示所有进程信息，连同命令行</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例4：-ps-与grep-常用组合用法，查找特定进程"><span class="nav-number">4.4.</span> <span class="nav-text">实例4： ps 与grep 常用组合用法，查找特定进程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例5：将目前属于您自己这次登入的-PID-与相关信息列示出来"><span class="nav-number">4.5.</span> <span class="nav-text">实例5：将目前属于您自己这次登入的 PID 与相关信息列示出来</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例6：列出目前所有的正在内存当中的程序"><span class="nav-number">4.6.</span> <span class="nav-text">实例6：列出目前所有的正在内存当中的程序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例7：列出类似程序树的程序显示"><span class="nav-number">4.7.</span> <span class="nav-text">实例7：列出类似程序树的程序显示</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实例8：找出与-cron-与-syslog-这两个服务有关的-PID-号码"><span class="nav-number">4.8.</span> <span class="nav-text">实例8：找出与 cron 与 syslog 这两个服务有关的 PID 号码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其他实例："><span class="nav-number">4.9.</span> <span class="nav-text">其他实例：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-可以用-管道和-more-连接起来分页查看"><span class="nav-number">4.9.1.</span> <span class="nav-text">1. 可以用 | 管道和 more 连接起来分页查看</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-把所有进程显示出来，并输出到ps001-txt文件"><span class="nav-number">4.9.2.</span> <span class="nav-text">2. 把所有进程显示出来，并输出到ps001.txt文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3-输出指定的字段"><span class="nav-number">4.9.3.</span> <span class="nav-text">3. 输出指定的字段</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
